package cn.yuyiling.jelly.kgai.controller;

import cn.yuyiling.jelly.kg.dto.KnowledgePointDTO;

import cn.yuyiling.jelly.kg.mapper.KnowledgePointMapper;
import cn.yuyiling.jelly.kg.mongodb.entity.KnowledgePoint;
import cn.yuyiling.jelly.kgai.api.KnowledgeAIService;
import cn.yuyiling.jelly.qa.dto.AnswerDTO;
import cn.yuyiling.jelly.qa.dto.QuestionDTO;

import cn.yuyiling.jelly.qa.mapper.AnswerMapper;
import cn.yuyiling.jelly.qa.mapper.QuestionMapper;
import cn.yuyiling.jelly.qa.mongodb.entity.Answer;
import cn.yuyiling.jelly.qa.mongodb.entity.Question;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/kgai")
public class KnowledgePointAIController {
    private static final Logger logger = LoggerFactory.getLogger(KnowledgePointAIController.class);

    @DubboReference(scope = "remote")
    private KnowledgeAIService knowledgeAIService;

    @PostMapping("/fill")
    public KnowledgePoint createKnowledgePoint(@RequestBody KnowledgePointDTO knowledgePointDTO) {
        logger.info("fill knowledge point with DTO: {}", knowledgePointDTO);
        KnowledgePoint knowledgePoint = KnowledgePointMapper.INSTANCE.dtoToEntity(knowledgePointDTO);
        return knowledgeAIService.fillKnowledgePoint(knowledgePoint);
    }

    @PostMapping("/extract_knowledgePoint")
    public Question extractKnowledgePoint(@RequestBody QuestionDTO questionDTO) {
        logger.info("extract knowledge point from question with DTO: {}", questionDTO);
        Question question = QuestionMapper.INSTANCE.dtoToEntity(questionDTO);
        return knowledgeAIService.extractKnowledgePoint(question);
    }

    @PostMapping("/evaluate_question")
    public Question evaluateQuestion(@RequestBody QuestionDTO questionDTO) {
        logger.info("evaluate question with DTO: {}", questionDTO);
        Question question = QuestionMapper.INSTANCE.dtoToEntity(questionDTO);
        return knowledgeAIService.evaluateDifficultyOfQuestion(question);
    }

    @PostMapping("/evaluate_answer")
    public Answer evaluateAnswer(@RequestBody AnswerDTO answerDTO) {
        logger.info("evaluate answer with DTO: {}", answerDTO);
        Answer answer = AnswerMapper.INSTANCE.dtoToEntity(answerDTO);
        return knowledgeAIService.evaluateAnswer(answer);

    }
}